/*
 * Created by SharpDevelop.
 * User: David
 * Date: 2006-12-19
 * Time: 23:05
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */

using System;

using patterns;

using Labb4.Pooman.Game;
using Labb4.Pooman.Cards;

namespace Labb4.Pooman.Players
{
	/// <summary>
	/// Base class for the different strategies of the ai players
	/// Implements the Template Method design pattern
	/// </summary>
	public abstract class AiStrategy : Observer<GameState>
	{
		#region members
		
		/// <summary>
		/// Reference to the ai methods of the current phase
		/// </summary>
		protected AiGameState			m_Phase;
		/// <summary>
		/// The ai methods of phase 2
		/// </summary>
		protected AiGameStatePhase2		m_Phase2;
		
		#endregion
		
		#region constructors
		
		/// <summary>
		/// Constructor, initializes members
		/// </summary>
		public AiStrategy() :
			base()
		{
			m_Phase = null;
			m_Phase2 = new AiGameStatePhase2();
		}
		
		#endregion
		
		#region methods
		
		/// <summary>
		/// Selects the cards to play
		/// </summary>
		/// <param name="player">Reference to the player selecting cards</param>
		public void PerformSelectCards(Player player)
		{
			m_Phase.SelectCardsAccordingToPhase(player);
		}
		
		/// <summary>
		/// Evaluates the quality of the won cards
		/// </summary>
		/// <param name="player">Reference to the player evaluating cards</param>
		/// <param name="cards">The cards to evaluate</param>
		/// <returns></returns>
		public Player.Evaluation PerformEvaluateWonCards(Player player, CardPile cards)
		{
			return m_Phase.EvaluateWonCardsPhase1(player, cards);
		}
		
		#endregion
		
		#region abstracts
		
		/// <summary>
		/// Gets a reference to the ai methods of phase 1 (this is the template method)
		/// </summary>
		/// <returns></returns>
		protected abstract AiGameState GetPhase1();
		
		#endregion
		
		#region overrides
		
		/// <summary>
		/// Changes the ai methods in accordance to the state changes of PoomanMain
		/// </summary>
		protected override void UpdateObserver()
		{
			base.UpdateObserver();
			
			if(m_SubjectsState is GameStatePhase1)
			{
				m_Phase = GetPhase1();
			}
			else
			{
				m_Phase = m_Phase2;
			}
		}
		
		#endregion
	}
}
